<?php

namespace App\Http\Controllers;

use App\Teacher;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class TeacherController extends Controller
{

	/**
	 * create a new teacher as user for auth
	 *
	 * @param Request $request
	 */
    public function create(Request $request)
    {
    	// world@123.fr secret
    	$teacher = new Teacher();
    	$teacher->name = $request->input('name');
    	$teacher->email = $request->input('email');
    	$teacher->password = bcrypt($request->input('password'));
    	$teacher->save();
    }

	/**
	 *  auth with another guard
	 *
	 * @param Request $request
	 * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
	 */
    public function auth(Request $request)
    {
    	$email = $request->input('email');
    	$password = $request->input('password');
	   // client1@yahoo.fr testtest auth
    	$email = 'world@123.fr';
    	$password = 'secret';

	    if (auth()->guard('teachers')->attempt(['email' => $email, 'password' => $password])) {
//    		dd(auth('teachers')->user()->email);
    		return view('/home');
	    } else {
    		dd(1212);
		    return back()->withErrors(['email' => 'Email or password are wrong.']);
	    }
    }

	/**
	 * if login then logout
	 */
    public function logout()
    {
    	if (auth('teachers')->user()) {
    		auth('teachers')->logout();
	    }
    }

	/**
	 * personalize auth is auth check
	 */
    public function isAuth()
    {
		dd(auth('teachers')->user()->email);
		if (auth('teachers')->check()) {
			dd(auth('teachers')->user()->email);
			dd(1212);
		}
		dd(auth('teachers'));
    }

}
